@using BlazorApp.Pages.Common
@using BlazorApp.Pages.Common.Html
@using BlazorApp.Pages.Common.Html.HTable
@using BlazorApp.Pages.Common.Metadata
@using BlazorApp.Pages.Event
@using BlazorApp.Pages.Pod
@using BlazorApp.Pages.Service
@using k8s.Models
@using Mapster
@inherits BlazorApp.Pages.Common.DrawerPageBase<k8s.Models.V1StatefulSet>
@if (StatefulSet != null)
{
    <StatefulSetAction Item="StatefulSet" MenuMode="MenuMode.Horizontal"></StatefulSetAction>
    <Divider Orientation="left" Style="font-weight:bold">@L["Metadata"]</Divider>
    <MetadataView Item="StatefulSet.Metadata" ExplainFieldPrefix="statefulSet"></MetadataView>
    <Divider Orientation="left" Style="font-weight:bold">@L["Spec"]</Divider>
    <HTable Bordered Column="1">
        <SelectorView Title=@L["Selector"] Selector="@StatefulSet.Spec.Selector.MatchLabels"></SelectorView>
        <PropertySimpleView Title=@L["ServiceName"] Item="@StatefulSet.Spec.ServiceName"
                            ExplainField="statefulSet.spec.serviceName">
        </PropertySimpleView>
        <PropertySimpleView Title=@L["Replicas"] Item="@StatefulSet.Spec.Replicas" ExplainField="statefulSet.spec.replicas"></PropertySimpleView>
        <PropertySimpleView Title=@L["MinReadySeconds"] Item="@StatefulSet.Spec.MinReadySeconds" ExplainField="statefulSet.spec.minReadySeconds"></PropertySimpleView>
        <PropertySimpleView Title=@L["RevisionHistoryLimit"] Item="@StatefulSet.Spec.RevisionHistoryLimit"
                            ExplainField="statefulSet.spec.revisionHistoryLimit">
        </PropertySimpleView>
        <PropertySimpleView Title=@L["Ordinals"] Item="@StatefulSet.Spec.Ordinals"
                            ExplainField="statefulSet.spec.ordinals" ShowInJson="true">
        </PropertySimpleView>
        @if (StatefulSet.Spec.PersistentVolumeClaimRetentionPolicy != null)
        {
            <HTableColumn Title=@L["PersistentVolumeClaimRetentionPolicy"]
                          ExplainField="statefulSet.spec.persistentVolumeClaimRetentionPolicy">
                @if (StatefulSet.Spec.PersistentVolumeClaimRetentionPolicy.WhenDeleted != null)
                {
                    <ColorfulTag>WhenDeleted: @StatefulSet.Spec.PersistentVolumeClaimRetentionPolicy.WhenDeleted</ColorfulTag>
                }
                @if (StatefulSet.Spec.PersistentVolumeClaimRetentionPolicy.WhenScaled != null)
                {
                    <ColorfulTag>WhenScaled: @StatefulSet.Spec.PersistentVolumeClaimRetentionPolicy.WhenScaled</ColorfulTag>
                }

            </HTableColumn>
        }
        <PropertyOptionView Title=@L["PodManagementPolicy"] Item="@StatefulSet.Spec.PodManagementPolicy"
                            ExplainField="statefulSet.spec.podManagementPolicy"
                            Options="@(new[] { "OrderedReady", "Parallel" })">
        </PropertyOptionView>
        <PropertyOptionView Title=@L["StrategyType"] Item="@StatefulSet.Spec.UpdateStrategy.Type"
                            ExplainField="statefulSet.spec.updateStrategy"
                            Options=@(new[] { "OnDelete", "RollingUpdate" })>
        </PropertyOptionView>
        <RollingUpdateView Title=@L["RollingUpdate"]
                           RollingUpdate="@(StatefulSet.Spec.UpdateStrategy.RollingUpdate.Adapt<V1RollingUpdateDeployment>())"
                           ExplainField="statefulSet.spec.updateStrategy.rollingUpdate">
            @if (StatefulSet.Spec.UpdateStrategy.RollingUpdate.Partition != null)
            {
                <ColorfulTag>Partition = @StatefulSet.Spec.UpdateStrategy.RollingUpdate.Partition </ColorfulTag>
            }
        </RollingUpdateView>
        <PropertySimpleView Title=@L["VolumeClaimTemplates"] Item="@StatefulSet.Spec.VolumeClaimTemplates"
                            ExplainField="statefulSet.spec.volumeClaimTemplates" ShowInJson="true">
        </PropertySimpleView>
    </HTable>
    <Divider Orientation="left" Style="font-weight:bold">@L["PodTemplate"]</Divider>
    <MetadataView Item="@StatefulSet.Spec.Template.Metadata" ExplainFieldPrefix="statefulSet"></MetadataView>
    <PodSpecView PodSpec="@StatefulSet.Spec.Template.Spec"></PodSpecView>
    <Divider Orientation="left" Style="font-weight:bold">@L["Status"]</Divider>
    <HTable Bordered Column="1">
        <PropertySimpleView Title=@L["AvailableReplicas"] Item="@StatefulSet.Status.AvailableReplicas" ExplainField="statefulSet.status.availableReplicas"></PropertySimpleView>
        <PropertySimpleView Title=@L["CollisionCount"] Item="@StatefulSet.Status.CollisionCount"
                            ExplainField="statefulSet.status.collisionCount">
        </PropertySimpleView>
        <PropertySimpleView Title=@L["Conditions"] Item="@StatefulSet.Status.Conditions" ExplainField="statefulSet.status.conditions" ShowInJson="true"></PropertySimpleView>
        <PropertySimpleView Title=@L["CurrentReplicas"] Item="@StatefulSet.Status.CurrentReplicas"
                            ExplainField="statefulSet.status.currentReplicas">
        </PropertySimpleView>
        <PropertySimpleView Title=@L["CurrentRevision"] Item="@StatefulSet.Status.CurrentRevision"
                            ExplainField="statefulSet.status.currentRevision">
        </PropertySimpleView>
        <PropertySimpleView Title=@L["ObservedGeneration"] Item="@StatefulSet.Status.ObservedGeneration" ExplainField="statefulSet.status.observedGeneration"></PropertySimpleView>
        <PropertySimpleView Title=@L["ReadyReplicas"] Item="@StatefulSet.Status.ReadyReplicas" ExplainField="statefulSet.status.readyReplicas"></PropertySimpleView>
        <PropertySimpleView Title=@L["Replicas"] Item="@StatefulSet.Status.Replicas" ExplainField="statefulSet.status.replicas"></PropertySimpleView>
        <PropertySimpleView Title=@L["UpdateRevision"] Item="@StatefulSet.Status.UpdateRevision"
                            ExplainField="statefulSet.status.updateRevision">
        </PropertySimpleView>
        <PropertySimpleView Title=@L["UpdatedReplicas"] Item="@StatefulSet.Status.UpdatedReplicas"
                            ExplainField="statefulSet.status.updatedReplicas">
        </PropertySimpleView>
    </HTable>

    <MiniPodListView ControllerByUid="@StatefulSet.Metadata.Uid"></MiniPodListView>
    @if (StatefulSet.Spec?.Template.Metadata.Labels is { Count: > 0 })
    {
        <MiniServiceListView Labels="@StatefulSet.Spec.Template.Metadata.Labels"></MiniServiceListView>
    }

    <MiniEventListView Uid="@StatefulSet.Metadata.Uid"></MiniEventListView>
}
